package com.upcode.weighing.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.upcode.weighing.domain.SysLogs;
import com.upcode.weighing.domain.SysOptLog;
import com.upcode.weighing.mapper.SysOptLogMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.upcode.weighing.service.SysOptLogService;
import com.upcode.weighing.vo.log.SysLogsPageListVo;
import com.upcode.weighing.vo.req.PageReqVo;
import com.upcode.weighing.vo.resp.PageRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;

/**
 * <p>
 * 日志信息表 服务实现类
 * </p>
 *
 * @author alex
 * @since 2019-04-10
 */
@Service
public class SysOptLogServiceImpl extends ServiceImpl<SysOptLogMapper, SysOptLog> implements SysOptLogService {

    @Autowired
    SysOptLogMapper sysOptLogMapper;

    //添加记录
    @Transactional(readOnly = false,rollbackFor = Exception.class)
    @Override
    public int addSysLogs(SysOptLog logs) {
        logs.setId(IdWorker.getId());
        return sysOptLogMapper.addSysLogs(logs);
    }

    //分页查询列表
    @Override
    public PageRespVo<SysLogsPageListVo> selectPageList(PageReqVo<SysLogsPageListVo> vo) {
        Page<SysLogsPageListVo> pageInfo = new Page<>(vo.getPage().getCurrentPage(), vo.getPage().getPageSize());//创建分页
        PageRespVo<SysLogsPageListVo> pageRespVo = new PageRespVo<SysLogsPageListVo>();
        IPage<SysLogsPageListVo> iPage = sysOptLogMapper.selectPageList(pageInfo,vo.getParams());
        pageRespVo.setPage(iPage);
        return pageRespVo;
    }

    @Override
    public boolean saveBatch(Collection<SysOptLog> entityList) {
        return super.saveBatch(entityList);
    }
}
